package Thread02;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Study02 extends Thread{
    private String url;
    private String name;

    public Study02(String url, String name) {
        this.url=url;
        this.name=name;
    }

    @Override
    public void run() {
        webDownloader webDownloader=new webDownloader();
        webDownloader.downloader(url,name);
        System.out.println(name+"的图片下载了。");
    }

    public static void main(String[] args) {
        Study02 s1=new Study02("https://tse3-mm.cn.bing.net/th/id/OIP-C.8l62NACpEMRVFlJaZNSXlgHaEK?w=332&h=187&c=7&r=0&o=5&pid=1.7","img1");
        Study02 s2=new Study02("https://tse1-mm.cn.bing.net/th/id/OIP-C.U_uj1lJJzLqyAf1WljIAVAHaE2?w=284&h=187&c=7&r=0&o=5&pid=1.7","img2");
        Study02 s3=new Study02("https://tse2-mm.cn.bing.net/th/id/OIP-C.3P-cWsf0agdOKV3_lAIvjQHaEo?w=290&h=181&c=7&r=0&o=5&pid=1.7","img3");
        s1.start();
        s2.start();
        s3.start();
    }
}

class webDownloader{
    public void downloader(String url,String name) {
        try {
            FileUtils.copyURLToFile(new URL(url), new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IO异常，downloader方法出现问题。");
        }
    }
}
